package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.pojo.Emp;
import com.example.zqh.pojo.params.EmpParams;
import com.example.zqh.pojo.params.OneStringOneNumber;
import com.example.zqh.service.EmpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-09-10
 */
@RestController
@RequestMapping("/emp")
@Api(tags = "员工表的增删改查(员工表将不做登录业务)")
public class EmpController {

    @Autowired
    EmpService empService;

    /**
      * @Author: zqh
      * @Date:
      * @Description: 添加一个新员工
    */
    @ApiOperation(value = "员工注册接口")
    @PostMapping("addANewEmployee")
    public RespBean addANewEmployee(@RequestBody EmpParams empParams){
        return empService.addANewEmployee(empParams);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 修改员工信息
    */
    @ApiOperation(value = "管理员修改员工信息接口，需要管理员权限")
    @PreAuthorize("hasRole('ROLE_admin')")
    @PostMapping("modifyEmployeeInformationInterface")
    public RespBean modifyEmployeeInformationInterface(@RequestBody Emp emp){
        return empService.modifyEmployeeInformationInterface(emp);
    }

    /**
      * @Author: zqh
      * @Date: 
      * @Description: 员工自己修改姓名接口
    */
    @ApiOperation(value = "员工自己修改名字接口")
    @PostMapping("employeeSOwnNameChangeInterface")
    public RespBean employeeSOwnNameChangeInterface(Integer id,String name){
        return empService.employeeSOwnNameChangeInterface(id,name);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 员工修改密码接口
    */
    @ApiOperation(value = "员工修改自己的密码")
    @PostMapping("employeesChangeTheirPasswords")
    public RespBean employeesChangeTheirPasswords(@RequestBody OneStringOneNumber oneStringOneNumber){
        return empService.employeesChangeTheirPasswords(oneStringOneNumber);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 员工修改电话接口
    */
    @ApiOperation(value = "员工修改电话接口")
    @PostMapping("employeeModifiesPhoneInterface")
    public RespBean employeeModifiesPhoneInterface(@RequestBody OneStringOneNumber oneStringOneNumber){
        return empService.employeeModifiesPhoneInterface(oneStringOneNumber);
    }
    
    /**
      * @Author: zqh
      * @Date: 
      * @Description: 员工修改头像接口
    */
    @ApiOperation(value = "员工修改头像接口")
    @PostMapping("employeeModificationAvatarInterface")
    public RespBean employeeModificationAvatarInterface(@RequestBody OneStringOneNumber oneStringOneNumber){
        return empService.employeeModificationAvatarInterface(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取所有员工的数量
    */
    @ApiOperation(value = "获取所有员工的数量（放行）")
    @GetMapping("getAllEmpty")
    public RespBean getAllEmpty(){
        return empService.getAllEmpty();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 分页查询员工
    */
    @ApiOperation(value = "分页查询员工（放行）")
    @GetMapping("queryEmployeesByPage")
    public RespBean queryEmployeesByPage(Integer page,Integer size){
        return empService.queryEmployeesByPage(page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 员工删除接口
    */
    @ApiOperation(value = "员工删除接口（需要管理员权限）")
    @DeleteMapping("employeeDeleteInterface")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean employeeDeleteInterface(Integer id){
        return empService.employeeDeleteInterface(id);
    }
}

